package com.study.d012Components;

import java.time.LocalDate;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class DatePickerMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane aPane = new AnchorPane();
 		DatePicker dp = new DatePicker(LocalDate.now());   //默认显示当前时间
 		aPane.getChildren().add(dp);
 		AnchorPane.setTopAnchor(dp, 30.0);
 		AnchorPane.setLeftAnchor(dp, 30.0);

 		/**
 		 * 使用setOnAction() 和valueProperty() 都可以进行监听
 		 */
 		dp.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				System.out.println("你选择的时间是:" + dp.getValue());
			}
		});


 		dp.valueProperty().addListener(new ChangeListener<LocalDate>() {
			@Override
			public void changed(ObservableValue<? extends LocalDate> observable, LocalDate oldValue,
					LocalDate newValue) {
				System.out.println("打印" + newValue);

			}
		});

		stage.setScene(new Scene(aPane,400,300));
		stage.show();

	}
}
